import {computed, CSSProperties, defineComponent, h} from 'vue'
import './icon.css'

export default defineComponent({
  name:"Icon",
  props:{
    prefix: {
      type: String,
      default: 'icon',
    },
    name: {
      type: String,
      required: false,
    },
    color: {
      type: String,
    },
    size: {
      type: [Number, String],
      default: 20,
    },
    spin: {
      type: Boolean,
      default: false,
    },
  },
  setup(props,){
    const className=props.spin ? 'my-icon svg-icon-spin' : 'my-icon'
    const symbolId = computed(() => `#${props.prefix}-${props.name}`)
    const getStyle = computed((): CSSProperties => {
      const { size } = props
      let s = `${size}`
      s = `${s.replace('px', '')}px`
      return {
        fontSize: s,
      }
    })
    return ()=>h('i',{class:className,style:getStyle.value},[
      h('svg',{class:'is-icon-'+props.name,'aria-hidden':true},[
        h('use',{href:symbolId.value,fill:props.color})
      ])
    ])
  },
})
